import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_web_view/browser_page.dart';
import 'package:oktoast/oktoast.dart';
import 'package:flutter_web_view/util/platform_util.dart';

void main(List<String> args) {
  _setupDesktop(args);
  _transparentStatusBar();
  runApp(const MyApp());
}

/// 配置桌面运行环境
void _setupDesktop(List<String> args) {
  if (!PlatformUtil.isDesktop()) {
    return;
  }
  WidgetsFlutterBinding.ensureInitialized();
}

/// 透明状态栏
void _transparentStatusBar() {
  if (!kIsWeb) {
    //Android平台 透明状态栏
    if (Platform.isAndroid) {
      SystemUiOverlayStyle systemUiOverlayStyle =
          const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return OKToast(
      child: MaterialApp(
        title: 'Flutter WebView',
        theme: ThemeData(
            primarySwatch: Colors.blue,
            // 不使用Material3风格
            useMaterial3: false),
        home: const MyHomePage(title: 'Flutter WebView'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return const Center(
      child: BrowserPage("https://uniapp.dcloud.io/"),
    );
  }
}
